##Table 7 - Run OLS regressions to estimate ATE of experiment
#variable consequences captures which version of question assigned
#consequences = 0 captures agreement with ""I would participate in the use of force to restore Donald Trump to the presidency"
#consequences = 1 adds [, even if some people are injured or killed]. 

##Estimate ATE using OLS without controls
T7A<-svyglm(itf~consequences,design=nd,family = gaussian(identity))

##Estimate ATE using OLS with controls for gender, race, age
T7B<-svyglm(itf~consequences+gender+as.factor(racethnicity)+age,design=nd, family = gaussian(identity))

#summarize results, OLS model 1 (no controls)
S7A<-summary(T7A)

#summarize results, OLS model 2 (with controls)
S7B<-summary(T7B)

#condense summaries for each model
T7C1<-round(rbind(S7A$coefficients[2,1],S7A$coefficients[2,2],S7A$coefficients[2,4]),3)
T7C2<-round(rbind(S7B$coefficients[2,1],S7B$coefficients[2,2],S7B$coefficients[2,4]),4)

#bind condensed summaries together
T7R13<-cbind(T7C1,T7C2)

#add a row stating controls
T7R4<-c("None","Gender,Race,Age")

#add a row stating number of observations
T7R5<-c(3145,3145)

#bind these all together
t7<-as.data.frame(rbind(T7R13,T7R4,T7R5))

#rename the rows to be more interpretable
rownames(t7)<-c("Estimated Average Treatment Effect (ATE)","Standard Error","P-value","Controls","obs")

#rename the columns to be more interpretable
colnames(t7)<-c("OLS Model 1","OLS Model 2")

#write out results
write.csv(t7,"../Main Results/T7.csv")


#Alternatively, you can see regression results in a conventional tabular format
stargazer(T7A,T7B,omit=c("gender","age","racethnicity","Constant"),omit.stat=c("ll","aic"),type="text",style="apsr",out="../Main Results/T7-stargazer.html")



